package org.limit.bookServe.vo;

import org.limit.bookServe.bean.User;
import org.limit.bookServe.service.UserService;
import org.limit.bookServe.service.impl.UserServiceImpl;
import org.limit.bookServe.utils.ActionFunction;

import java.util.Map;
import java.util.Objects;

import static org.limit.bookServe.utils.BaseClass.*;

/**
 * @author 1.
 * @version 1.0
 * @description:
 * @date 2023/11/5 1:15
 */
public class UserVO {
    //    private List<User> userList;
    private final UserService userService;

    public UserVO(Map<String, User> userList) {
//        this.userList = userList;
        this.userService = new UserServiceImpl(userList);
    }

    //注册
    public void register() {
        userService.register();
    }

    //登录
    public void login() {
        userService.login();
    }

    //查找用户
    public void findUserInfo() {
        println("请输入您想要查找的用户名:");
        String username = input.nextLine();
        if (!Objects.equals(username, "")) {
            userService.findUserByUserName(username);
        } else {
            println("用户名不规范！");
        }
    }

    //显示所有用户
    public void showAllUserAcc() {
        userService.showAllUserInfo();
    }

    //禁用用户账号
    public void bannedUserAcc() {
        changeUserAccPattern(new ActionFunction() {
            @Override
            public <T> void run(T t) {
                userService.bannedUserAcc((String) t);
            }
        });
    }

    //修改用户帐号状态
    public void changedUserAccStatus() {
        changeUserAccPattern(new ActionFunction() {
            @Override
            public <T> void run(T t) {
                userService.changedUserStatus((String) t);
            }
        });
    }

    //修改用户帐号方法模板
    private void changeUserAccPattern(ActionFunction action) {
        print("请输入用户id: ");
        String userId = input.nextLine();
        if (!Objects.equals(userId, "")) {
            //执行
            action.run(userId);
        } else {
            println("用户id不规范！");
        }
    }

}
